/*
 *   Copyright (C) 2010  Jens Kieselbach
 * 
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 * 
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 * 
 *   You may obtain a copy of the License at http://www.gnu.org/licenses/gpl.html
 */

package de.kieselbach.swing.table

import javax.swing.*
import javax.swing.table.*

import java.awt.Component

class ColorTableCellRenderer extends DefaultTableCellRenderer {

    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {

        if(value instanceof TableCellValue) {
			super.getTableCellRendererComponent(table, value.value, isSelected, hasFocus, row, column)
            horizontalAlignment = value.horizontalAlignment
			
			if(isSelected) {
				setBackground(table.getSelectionBackground())
			}
			else {
	            if(value.background != null) {
	                setBackground(value.background)
	            }
				else {
					setBackground(table.getBackground())
				}
			}
        }
        else {
            super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column)
			setBackground(table.getBackground())
        }
		
        return this
    }
}

